package com.movitech.mobile.cz.base.purchase.bizservice.impl;

import com.google.common.collect.Lists;
import com.movitech.mobile.cz.base.common.license.LicenseUtil;
import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.purchase.bizservice.ExtWFlowFormStrategicProtocolService;
import com.movitech.mobile.cz.base.purchase.entity.ext.ExtWFlowFormStrategicProtocol;
import com.movitech.mobile.cz.base.purchase.entity.ext.ExtWStrategicProtocol;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormStrategicProtocolService;
import com.movitech.mobile.cz.base.purchase.service.WStrategicProtocolService;
import com.movitech.mobile.cz.base.util.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-29
 */
@Service
public class ExtWFlowFormStrategicProtocolServiceImpl implements ExtWFlowFormStrategicProtocolService {

    @Autowired
    private WFlowFormStrategicProtocolService wFlowFormStrategicProtocolService;
    @Autowired
    private WStrategicProtocolService wStrategicProtocolService;

    @Override
    public List<ExtWFlowFormStrategicProtocol> inserByProtocolIds(List<String> ids,String formId) {
        LicenseUtil.INSTANCE.validate();
        List<ExtWFlowFormStrategicProtocol> extWFlowFormStrategicProtocols = Lists.newArrayList();
        List<ExtWStrategicProtocol> wStrategicProtocols = wStrategicProtocolService.findByIds(ids);
        for(ExtWStrategicProtocol wStrategicProtocol:wStrategicProtocols){
            ExtWFlowFormStrategicProtocol extWFlowFormStrategicProtocol = new ExtWFlowFormStrategicProtocol();
            extWFlowFormStrategicProtocol.setSuppliersName(wStrategicProtocol.getSupplierName());
            extWFlowFormStrategicProtocol.setBaseFeilds(UserUtils.getCurrentUserId(),"",
                    CommonConstants.DEL_FLAG_NORMAL, true);
            extWFlowFormStrategicProtocol.setFlowFormId(formId);
            extWFlowFormStrategicProtocol.setRegionalCompanyId(wStrategicProtocol.getRegionalCompanyId());
            extWFlowFormStrategicProtocol.setSupplierId(wStrategicProtocol.getSupplierId());
            extWFlowFormStrategicProtocol.setStrategicName(wStrategicProtocol.getStrategicName());
            extWFlowFormStrategicProtocol.setStrategicId(wStrategicProtocol.getId());
            extWFlowFormStrategicProtocol.setStrategicCategoryName(wStrategicProtocol.getStrategicCategoryName());
            extWFlowFormStrategicProtocol.setProtocolStartTime(wStrategicProtocol.getProtocolStartTime());
            extWFlowFormStrategicProtocol.setProtocolEndTime(wStrategicProtocol.getProtocolEndTime());
            wFlowFormStrategicProtocolService.insert(extWFlowFormStrategicProtocol);

            extWFlowFormStrategicProtocols.add(extWFlowFormStrategicProtocol);
        }
        return extWFlowFormStrategicProtocols;
    }
}
